package com.lagou.springboot.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lagou.springboot.mapper.ArticleMapper;
import com.lagou.springboot.pojo.Article;
import com.lagou.springboot.pojo.ArticleExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public PageInfo<Article> articleList(Integer pageNum) {
        if (pageNum==null){
            pageNum = 1;
        }
        PageHelper.startPage(pageNum, 5);
        ArticleExample example = new ArticleExample();
        List<Article> articles = articleMapper.selectByExample(example);
        PageInfo<Article> pageInfo = new PageInfo<Article>(articles);

        return pageInfo;
    }
}
